
<div class="app-content-body ">

    <div class="bg-light lter b-b wrapper-md hidden-print">
      <h1 class="m-n font-thin h3">会员信息</h1>

    </div>

    <form id="form-container">
      <div class="form_title">
        <div class="my_hd">
          会员编辑
          <div class="pull-right delete" dx-toggle="button" dx-options='{"type": "danger"}'>删除</div>
        </div>
        <div class="crud-container crud-reset">
          <div class="row"> 
            <div class="col-sm-12">
              <div id="form"></div>
            </div>
          </div>          
          <div class="row">
            <div class="col-sm-12 text-right">
              <div style="margin: 15px 0;">
                <div id="cancel"></div>
                <div id="save_build"></div>
                <div id="save"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </form>
</div>

<script>
  $(function () {  
    var form = $("#form").dxForm(
    }).dxForm("instance");

    $("#content").one("route.loaded", function(e, context) {
      var store = $.crudStore(API("members")), id = context.params.id;

      store.byKey(id).then(function (resp) {
          form.updateData(resp);
      });

      $("#form-container").on("submit", function(e) {
          store.update(id, form.option('formData')).then(function (resp) {
            console.log(resp);
          });

          return false;
      });

      $("#form-container .delete").click(function () {
        DevExpress.ui.dialog.confirm("确认删除吗?", "请确认").done(function (dialogResult) {
          if (dialogResult) {
            store.remove(id).then(function (resp) {
              console.log(resp);
              DevExpress.ui.notify({
                  message: "已删除",
              }, "success", 1000);
            });
          }
        });
        return false;
      });

    });

    

    $("#save").dxButton({
        text: "保存",
        type: "success",
        useSubmitBehavior: true,
        validationGroup: "customerData"
    });
    $("#save_build").dxButton({
        text: "保存并新建联系人",
        type: "success",
        useSubmitBehavior: true,
        validationGroup: "customerData"
    });
    $("#cancel").dxButton({
        text: "取消",
        type: "normal"
    });
  });
</script>